package engine;

import java.awt.Point;

import movables.Snake;
import junit.framework.TestCase;

public class testCell extends TestCase {
	
	Board board = new Board(30,0,0,0,false);
	Snake snake1 = new Snake(board, new Point(1,1), new Point(10,10));
	Snake snake2 = new Snake(board, new Point(2,2), new Point(10,10));
	Cell cell = new Cell(new Point(2,1));
	
	public testCell() {
		assertNotNull(new Cell(new Point(2,1)));
	}

	public void testEnterCell() { 
		cell.setCelltype(CellType.FLOOR);
		assertEquals(cell.enterCell(snake1), true);
	}

	public void testQuitCell() {
		cell.quitCell(snake1);
		assertEquals(cell.hasAnotherSnake(), false);
	}

	public void testHasAnotherSnake() {
		cell.setCelltype(CellType.FLOOR);
		assertEquals(cell.hasAnotherSnake(), false);
		cell.enterCell(snake1);
		assertEquals(cell.hasAnotherSnake(), true);

	}

	public void testHasJumpingSnake() {
		cell.setCelltype(CellType.FLOOR);
		assertEquals(cell.hasJumpingSnake(), false);
		snake2.setCanJump(true);
		cell.enterCell(snake1);
		cell.enterCell(snake2);
		assertEquals(cell.hasJumpingSnake(), true);

	}

	public void testGetJumpingSnake() {
		assertNull(cell.getJumpingSnake());
		cell.setCelltype(CellType.FLOOR);
		snake2.setCanJump(true);
		cell.enterCell(snake1);
		cell.enterCell(snake2);
		assertEquals(snake2, cell.getJumpingSnake());
	}

	public void testGetPos() {
		Point correctPoint = new Point(2,1);
		Point wrongPoint = new Point(2,1);
		assertEquals(correctPoint, cell.getPos());
		assertNotSame(wrongPoint, cell.getPos());
		
	}

	public void testGetCelltype() {
		cell.setCelltype(CellType.FLOOR);
		assertEquals(CellType.FLOOR, cell.getCelltype());
	}

	public void testSetCelltype() {
		cell.setCelltype(CellType.FLOOR);
		assertEquals(CellType.FLOOR, cell.getCelltype());
		cell.setCelltype(CellType.FOOD);
		assertEquals(CellType.FOOD, cell.getCelltype());
	}

	public void testToString() {
		assertNotNull(cell.toString());
	}

	public void testWarn() {
		cell.setCelltype(CellType.FLOOR);
		cell.enterCell(snake1);
		new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(600);
				} catch (InterruptedException e) {e.printStackTrace();}
				cell.quitCell(snake1);;
				cell.Warn();
			}
		}).start();
		assertEquals(true, cell.enterCell(snake2));
		
	}

}
